﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KinectAssistant
{
    public partial class ImageView : Form
    {

        public string currentPic;

        private Point mouse_offset;

        public ImageView()
        {
            InitializeComponent();
        }

        private void ImageView_Load(object sender, EventArgs e)
        {
            this.picBox_main.ImageLocation = currentPic;
        }

            private void button_up_Click(object sender, EventArgs e)
            {
                float w = this.picBox_main.Width * 1.2f;
                float h = this.picBox_main.Height * 1.2f;
                this.picBox_main.Size = Size.Ceiling(new SizeF(w, h));
                picBox_main.Left = (this.Width - picBox_main.Width) / 2;
                picBox_main.Top = (this.Height - picBox_main.Height) / 2;
            }


            private void button_down_Click(object sender, EventArgs e)
            {
                //if (picBox_main.Width > PicboxWidth && picBox_main.Height > PicboxHeight)
                //{
                //    float w = this.picBox_main.Width * 0.8f; //每次縮小 20%
                //    float h = this.picBox_main.Height * 0.8f;
                //    this.picBox_main.Size = Size.Ceiling(new SizeF(w, h));
                //    picBox_main.Left = (this.Width - picBox_main.Width) / 2;
                //    picBox_main.Top = (this.Height - picBox_main.Height) / 2;
                //}

                float w = this.picBox_main.Width * 0.8f; //每次縮小 20%
                float h = this.picBox_main.Height * 0.8f;
                this.picBox_main.Size = Size.Ceiling(new SizeF(w, h));
                picBox_main.Left = (this.Width - picBox_main.Width) / 2;
                picBox_main.Top = (this.Height - picBox_main.Height) / 2;
            }

            private void picBox_main_MouseDown(object sender, MouseEventArgs e)
            {
                mouse_offset = new Point(-e.X, -e.Y);
            }

            private void picBox_main_MouseMove(object sender, MouseEventArgs e)
            {
                ((Control)sender).Cursor = Cursors.SizeAll;//设置拖动时鼠标光标
                if (e.Button == MouseButtons.Left)
                {
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouse_offset.X, mouse_offset.Y);//设置偏移
                    ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
                    //this.picBox_main.Location = this.picBox_main.Parent.PointToClient(mousePos);
                }
            }

            public void amplifyImage()
            {
                float w = this.picBox_main.Width * 1.2f;
                float h = this.picBox_main.Height * 1.2f;
                this.picBox_main.Size = Size.Ceiling(new SizeF(w, h));
                picBox_main.Left = (this.Width - picBox_main.Width) / 2;
                picBox_main.Top = (this.Height - picBox_main.Height) / 2;
            }

            public void reduceImage()
            {

                float w = this.picBox_main.Width * 0.8f;
                float h = this.picBox_main.Height * 0.8f;
                this.picBox_main.Size = Size.Ceiling(new SizeF(w, h));
                picBox_main.Left = (this.Width - picBox_main.Width) / 2;
                picBox_main.Top = (this.Height - picBox_main.Height) / 2;
            }

            public void moveImage(Point track)
            {
                Point picPos = this.picBox_main.Location;
                picPos.Offset(track.X, -track.Y);
                this.picBox_main.Location = this.picBox_main.Parent.PointToClient(picPos);
            }
            //float PicboxWidth;
            //float PicboxHeight;

            //private void Picbox_Load(object sender, EventArgs e)
            //{
            //    PicboxWidth = picBox_main.Width;
            //    PicboxHeight = picBox_main.Height;
            //}

            //protected override void OnResize(EventArgs e)
            //{
            //    if (WindowState == FormWindowState.Maximized)
            //    {
            //        picBox_main.Left = (this.Width - picBox_main.Width) / 2;
            //        picBox_main.Top = (this.Height - picBox_main.Height) / 2;
            //    }
            //}

            //private void Picbox_ClientSizeChanged(object sender, EventArgs e)
            //{
            //    if (this.Width < PicboxWidth || this.Height < PicboxHeight)
            //    {
            //        float widh = this.Width * 0.8f;
            //        float height = this.Height * 0.8f;
            //        this.picBox_main.Size = Size.Ceiling(new SizeF(widh, height));
            //    }
            //    else if (this.Width > PicboxWidth && this.Height > PicboxHeight)
            //    {
            //        this.picBox_main.Size = Size.Ceiling(new SizeF(PicboxWidth, PicboxHeight));
            //    }
            //    picBox_main.Left = (this.Width - picBox_main.Width) / 2;
            //    picBox_main.Top = (this.Height - picBox_main.Height) / 2;
            //}

        }
    }
